<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>编辑热点事件</title>
<style type="text/css">
	body{
		padding:20px 100px;
	}
	.one{
		background-color:skyblue;
		padding:6px;
		margin-bottom:15px;
	}
	#detail{
		text-indent:2em;
	}
	#comments{
		max-height: 400px;
		overflow: auto;
	}
</style>
<link rel="stylesheet" href="themes/default/default.css" />
	<link rel="stylesheet" href="plugins/code/prettify.css" />
	<script charset="utf-8" src="kindeditor-all.js"></script>
	<script charset="utf-8" src="lang/zh-CN.js"></script>
	<script charset="utf-8" src="plugins/code/prettify.js"></script>
</head>
<body>
	<h1>编辑热点事件</h1>
	<div>
		<p>关键字:<input id="keyWord"/></p>
		<p>内容:<textarea id="hotContent" name="content1" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;"></textarea></p>
		<p>搜索指数:<input id="searchSum" type="number"/></p>
		<p><button onclick="updateevent()">提交</button></p>
	</div>
</body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.params.js"></script>
<script type="text/javascript">
var hid = 0; //事件id
var createDate = null
var uid = 0; //发帖人id
var userobj = null

$(function(){
	hid = $.query.get("hid")
	//alert(hid)
	getEvent()
	autologin()
})

function getEvent(){
	$.getJSON("hotevents/fetch",{"id":hid},function(res){
		let event = res.data
		console.log(event)
		createDate = event.createDate
		$("#keyWord").val(event.keyWord)
		$("#hotContent").val(event.hotContent)
		$("#searchSum").val(event.searchSum)
		uid = event.uid
		KindEditor.create('textarea[name="content1"]', {
			cssPath : 'plugins/code/prettify.css',
			uploadJson : '/upload/uploadjson',
			items:[
		        'source', '|', 'undo', 'redo', '|', 'preview', 'template', 'code', 'cut', 'copy', 'paste',
		        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
		        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
		        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
		        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
		        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
		        'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
		        'anchor', 'link', 'unlink', '|', 'about'
			],
			afterBlur: function () { this.sync(); }
		});
		
		prettyPrint();
	})
}

function updateevent(){
	if(userobj == null){
		alert("你还没有登录")
		return
	}
	let params = {
			"keyWord":$("#keyWord").val(),
			"hotContent":$("#hotContent").val(),
			"searchSum":$("#searchSum").val(),
			"id":hid,
			"createDate":createDate,
			"uid":uid
		}
	$.ajax({
		url:"hotevents/update",
		type:"POST",
		data:params,
		dataType:"json",
		success:function(res){
			//成功返回，还有再判断自定义状态码
			if(res.resultCode == 200){
				let comment = res.data
				console.log(comment)
				alert("修改热点事件成功")	
				location.href="index.html"
			}else{
				alert("修改失败，错误编号:" + res.resultCode+",异常提示:" + res.message)
			}
		},
		error:function(res){
			//console.log(res)
			//提取返回内容中的字符串，再强转成json对象
			let resjson = JSON.parse(res.responseText)
			
			let code = resjson.resultCode
			let message = resjson.message
			alert("错误编码:" + code + ": " + message)
		}
	})
}

function autologin(){
	$.getJSON("user/autologin",function(res){
		if(res.resultCode == 200){
			userobj = res.data;
		}
	})
}
</script>
</html>